<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-api',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'api\controllers',
    'language'=>'zh-CN',
    'timeZone' => 'Asia/Shanghai',
    'charset'=>'utf-8',
    'bootstrap' => ['log'],
    'modules' => [
        'v1' => [
            'class' => 'api\modules\v1\Modules',
        ],
        'v2' => [
            'class' => 'api\modules\v2\Modules',
        ],
    ],
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
            'keyPrefix' => 'lrb_',       // 唯一键前缀
        ],
        'request' => [
            'csrfParam' => '_csrf-api',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ],
        ],
        'response' => [ //自定义错误响应
            'class' => 'yii\web\Response',
            'on beforeSend' => function ($event) {
                $response = $event->sender;
                if ($response->data !== null) {
                    $response->data = [
                        'success' => $response->isSuccessful,
                        'data' => $response->data,
                    ];
                    $response->statusCode = 200;
                }
            },
        ],
        'user' => [
            'identityClass' => 'api\common\models\User',
            //'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-api', 'httpOnly' => true],
            'enableAutoLogin' => true,
            'enableSession'=>false
        ],
        'session' => [
            // this is the name of the session cookie used for login on the api
            'name' => 'advanced-api',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'v1/site/error',
        ],

        //'GET versions' => 'version',
        //'GET search/<id:\d+>' => 'search', //代表搜索一个指定id的用户 searches/1
        //'POST newusers' => 'add'
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['v1/reg','v1/code','v1/login','v1/user','v1/category','v1/news','v1/like','v1/comment','v1/collect','v1/msg','v1/opinion','v1/third','v1/attention','v1/authentication','v1/activity','v1/reward','v1/recommend','v1/publish','v1/simlogin','v1/simuser','v1/shield','v1/report','v1/commentpc','v1/likepc','v1/publishpc','v1/reward','v1/pay','v1/recommendpc','v1/reportpc','v1/withdraw','v1/adv','v1/ucenter','v1/ucenter-third'],'pluralize' => false,
                    'extraPatterns' => [ //额外模式配置
                        'GET <action:\w+>/<id:\d+>' => '<action>',
                        'GET <action:\w+>' => '<action>',
                        'POST <action:\w+>' => '<action>',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['v2/reg','v2/code','v2/login','v2/user','v2/category','v2/news','v2/like','v2/comment','v2/collect','v2/msg','v2/opinion','v2/third','v2/attention','v2/authentication','v2/activity','v2/reward','v2/recommend','v2/publish','v2/simlogin','v2/simuser','v2/shield','v2/report','v2/commentpc','v2/likepc','v2/publishpc','v2/reward','v2/pay','v2/recommendpc','v2/reportpc','v2/withdraw','v2/adv','v2/ucenter','v2/ucenter-third'],'pluralize' => false, // true Yii将在末端使用的控制器的名称自动变为复数
                    'extraPatterns' => [ //额外模式配置
                        'GET <action:\w+>/<id:\d+>' => '<action>',
                        'GET <action:\w+>' => '<action>',
                        'POST <action:\w+>' => '<action>',
                    ],
                ]
            ],
        ],
    ],
    'params' => $params,
];
